package it.trekker.interceptors;

import it.trekker.prefetch.ejb.ExcursionDAOWithPrefetch;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import org.apache.log4j.Logger;

public class ExcursionDAOWithPrefetchLogger {
	
	@AroundInvoke
	public Object log(InvocationContext ctx) throws Exception {
		
		ExcursionDAOWithPrefetch target = (ExcursionDAOWithPrefetch) ctx.getTarget();
		String targetName = target.getClass().getCanonicalName();
		String methodName = ctx.getMethod().getName();
		
		Logger logger = Logger.getLogger(targetName);
		
		logger.info("start " + methodName);
		
		Object retVal = ctx.proceed();
		
		target.getCache().logAllCache();
		
		logger.info("end " + methodName);
		
		return retVal;
	}
}
